﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Ana_Form
{
    public partial class Form_Malzeme : Form
    {
        DepodataDataContext db;
        Malzeme malzeme;

        public Malzeme Malzeme
        {
            get { return malzeme; }
            set { malzeme = value; }
        }
        Marka marka;
        Model model;
        public Form_Malzeme()
        {
            InitializeComponent();
            db = new DepodataDataContext();
            MalzemeleriListele();

            MarkaSirala();

        }

        public Form_Malzeme(ref DepodataDataContext db)
        {
            InitializeComponent();
            this.db = db;
            MalzemeleriListele();

            MarkaSirala();
        }

        private void MarkaSirala()
        {
            var soru = from x in db.Markas orderby x.Adi select x;
            foreach (var item in soru)
            {
            }
        }

        private void MalzemeleriListele()
        {
            listmalzeme.Items.Clear();
            listmalzeme.Groups.Clear();
            var soru = from x in db.Malzemes
                       where x.Hack == false
                       // orderby x.Depo == 1
                       select x;
            foreach (var item in soru)
            {
                ListViewItem litem = new ListViewItem();
                litem.Text = item.id.ToString();
                litem.SubItems.Add(item.MalzemeCinsi.Adi);
            }
        }

        private void lblekle_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            btnekle.Enabled = true;
            btnekle.Tag = 1;
            btnekle.Text = "Ekle";
        }

        private void lblduzenle_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            btnekle.Text = "Değiştir";
            btnekle.Tag = 0;
            btnekle.Enabled = true;
            btnsil.Enabled = true;
        }

        private void listmalzeme_SelectedIndexChanged(object sender, EventArgs e)
        {
            Malzeme = (from x in db.Malzemes
                       where x.id == int.Parse(listmalzeme.SelectedItems[0].Text)
                       select x).FirstOrDefault();
        }


        private void btnekle_Click(object sender, EventArgs e)
        {
            if (btnekle.Tag.ToString() == "1")
            {

            }
            else
            {

            }
            btnekle.Enabled = false;
            btnsil.Enabled = false;
        }


        private void btniptal_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnmarkaekle_Click(object sender, EventArgs e)
        {
            Form_Marka frm = new Form_Marka();
            frm.ShowDialog();
        }

        private void cbmarka_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void Modelsirala()
        {
        }


        private void Form_Malzeme_Resize(object sender, EventArgs e)
        {

        }

        private void btnekle_Click_1(object sender, EventArgs e)
        {
            Form_MalzemeGirdisi frm = new Form_MalzemeGirdisi(ref db);
            if (frm.ShowDialog() == DialogResult.OK)
            {

            }
        }

        private void btniptal_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnduzenle_Click(object sender, EventArgs e)
        {

        }

        private void btnsil_Click(object sender, EventArgs e)
        {

        }

        private void btnTamam_Click(object sender, EventArgs e)
        {

        }
    }
}
